SERVER = true
--SERVER_DEBUG = true
__TESTING = true



BASEPATH = SERVER and "client/" or ""
math.randomseed(os.time())
love = nil
enet = require "enet"
class=require "client/lib/middleclass"
delay= require "client/lib/delay"
tween = require "client/lib/tween"
bump = require "client/lib/bump"
bitser = require "client/lib/bitser"
sock = require "client/lib/sock"
require "client/scr/net"
require "client/game_mode"
Base = require "client/object/base"
Tank = require "client/object/tank"
Bullet = require "client/object/bullet"
Ding = require "client/object/ding"
Map = require "client/object/map"
Item = require "client/object/item"
HQ = require "client/object/headquarter"



if SERVER then
    serverRate = 1/20
    local socket = require("socket")
    net:serverInit()
    userDB = require("client/scr/userDB"):init()
    local ot = socket.gettime()
    local function serverUpdate()
        local nt = socket.gettime()
        local dt = nt-ot
        delay:update(dt)
        net:update(dt)
        socket.sleep(serverRate)
        ot = nt
    end
    if SERVER_DEBUG then
        while true do
            serverUpdate()
        end
    else
        while true do
            local ok,err = pcall(serverUpdate)
            if not ok then
                print(err)
                net:sendMail(err)
                net:restartServer()
            end
        end
    end
end

